import { message, TableColumnProps } from "ant-design-vue";
import { Ref, watch } from "vue";

export function useReceiptTable({
  props,
  columns,
}: {
  props: Readonly<{ disableOper?: boolean; [key: string]: any }>;
  columns: Ref<TableColumnProps[]>;
}) {
  watch(
    () => props.disableOper,
    (val) => {
      const index = columns.value.findIndex((el) => el.key === "oper");
      if (val) {
        if (index >= 0) {
          columns.value.splice(index, 1);
        }
      } else {
        if (index === -1) {
          columns.value.push({
            title: "操作",
            key: "oper",
            width: 100,
          });
        }
      }
    },
    { immediate: true }
  );
}
